<template>
    <div class="app-container form-demo">
        <el-card shadow="always" v-show="showSearch">
            <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
                <el-form-item label="供应商" prop="orderNo">
                    <el-select v-model="queryParams.supplierId" value-key="" placeholder="请选择供应商" clearable filterable
                        @change="handleQuery">
                        <el-option v-for="item in supplierList" :key="item.id" :label="item.supplierName"
                            :value="item.id">
                        </el-option>
                    </el-select>

                </el-form-item>
                <el-form-item label="商品名称" prop="orderNo">
                    <el-input v-model="queryParams.goodsName" placeholder="请输入商品名称" clearable
                        @keyup.enter="handleQuery" />
                </el-form-item>
                <el-form-item label="货号" prop="itemNo">
                    <el-input v-model="queryParams.itemNo" placeholder="请输入货号" clearable @keyup.enter="handleQuery" />
                </el-form-item>
                <!-- <el-form-item label="商品条码" prop="orderNo">
                    <el-input v-model="queryParams.orderNo" placeholder="请输入商品条码" clearable
                        @keyup.enter="handleQuery" />
                </el-form-item>
                <el-form-item label="商品品牌" prop="orderNo">
                    <el-input v-model="queryParams.orderNo" placeholder="请输入商品品牌" clearable
                        @keyup.enter="handleQuery" />
                </el-form-item> -->
                <!-- <el-form-item label="审核状态" prop="orderNo">
                    <el-select v-model="queryParams.status" value-key="" placeholder="" clearable filterable >
                        <el-option v-for="item in material_audit_status" :key="item.value" :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>

                </el-form-item> -->
                <el-form-item>
                    <el-button type="primary" @click="handleQuery">搜索</el-button>
                    <el-button @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>

        <el-card class="box-card" shadow="always" :body-style="{ padding: '20px' }">
            <!-- card body -->
            <el-row :gutter="10" class="mb8">

                <el-radio-group v-model="queryParams.status" @change="statusChange">
                    <el-radio-button label="">全部</el-radio-button>
                    <el-radio-button v-for="(item, index) in material_audit_status" :key="index" :label="item.value">{{
                        item.label
                        }}</el-radio-button>
                </el-radio-group>
                <right-toolbar :v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>

            <el-table border v-loading="loading" :data="dataSource" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" align="center" :selectable="selectHandle" />
                <el-table-column label="#" type="index"> </el-table-column>
                <el-table-column label="商品主图" align="center" prop="warehouseName" width="150">
                    <template #default="scope">
                        <el-image style="width: 50px; height: 50px;" :src="scope.row.packImg" lazy>
                            <template #error>
                                <div class="image-slot">
                                    <img style="width: 50px; height: 50px;" src="@/assets/goods/order/img_failure.svg"
                                        alt="">
                                </div>
                            </template>
                        </el-image>
                    </template>
                </el-table-column>
                <el-table-column label="商品货号" align="center" prop="itemNo" />
                <el-table-column label="商品名称" align="center" prop="goodsName" />
                <el-table-column label="供应商" align="center" prop="supplierName" />
                <!-- <el-table-column label="共享时间" align="center" prop="warehouseName" />
                <el-table-column label="库存" align="center" prop="warehouseName" /> -->
                <!-- <el-table-column label="上架状态" align="center" prop="shelfStatus">
                    <template #default="scope">
                        <el-tag v-if="scope.row.shelfStatus == 1" type="success">已上架</el-tag>
                        <el-tag v-else type="danger">未上架</el-tag>
                    </template>
                </el-table-column> -->
                <el-table-column label="审核状态" align="center" prop="status">
                    <template #default="scope">
                        <el-tag v-if="scope.row.status == 0" type="info">未审核</el-tag>
                        <el-tag v-else-if="scope.row.status == 1" type="success">已审核</el-tag>
                        <el-tag v-else-if="scope.row.status == 2" type="warning">已拒绝</el-tag>
                        <el-tag v-else type="danger">已禁用</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template #default="scope">
                        <span v-if="['0', '3'].includes(scope.row.status)">
                            <el-button type="text" @click="handleAudit(scope.row, 1)">{{ scope.row.status == '3' ? '启用'
                                :
                                '通过' }}</el-button>

                            <el-divider v-if="['0', '1'].includes(scope.row.status)" direction="vertical"></el-divider>

                        </span>
                        <span v-if="['0'].includes(scope.row.status)">
                            <el-button type="text" @click="handleAudit(scope.row, 2)">拒绝</el-button>
                            <el-divider direction="vertical" v-if="['1'].includes(scope.row.status)"></el-divider>
                        </span>
                        <span v-if="['1'].includes(scope.row.status)">
                            <el-button type="text" @click="handleAudit(scope.row, 3)">禁用</el-button>
                        </span>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" v-model:page.sync="queryParams.pageNum"
                v-model:limit.sync="queryParams.pageSize" @pagination="getList" />
        </el-card>
        <addForm ref="modelForm"></addForm>
    </div>
</template>

<script>
import addForm from './modules/addForm.vue';
import listMixin from '@/mixins/listMixin';
import request from '@/utils/request';
import { getSupplierAllList } from '@/api/goods/supplier'
export default {
    name: "materialExamine",
    dicts: ["inventory_status", "counting_method"],
    components: {
        addForm
    },
    mixins: [listMixin],
    data() {
        return {
            showSearch: true,
            queryParams: {
                orderNo: '',
                pageNum: 1,
                pageSize: 10,
                status: 0
            },
            loading: false,
            dataSource: [],
            material_audit_status: [],//商品审核状态
            material_rack_status: [],//商品上架状态
            total: 0,
            statusArr: [
                { label: '全部', value: '' },
                { label: '未审核', value: '1' },
                { label: '已审核', value: '2' },
                { label: '已拒绝', value: '3' },
            ],
            urls: {
                list: '/order/supplierGoods/list',
                delete: '/order/supplierGoods',
                auditUrl: '/order/supplierGoods/audit'
            },
        };
    },
    created() {
        this.getDicts(['material_audit_status', 'material_rack_status']);
        this.getSupplierAllList();
    },
    methods: {
        statusChange(val) {
            this.queryParams.status = val;
            this.getList();
        },
        handleAudit(row, type) {
            const msgType = type == 1 ? '通过' : type == 2 ? '拒绝' : '禁用';
            this.$modal.confirm(`是否确认${msgType}？`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let params = {
                    url: this.urls.auditUrl,
                    method: 'post',
                    data: {
                        id: row.id,
                        status: type
                    }
                }
                request(params).then(res => {
                    this.$modal.msgSuccess(type == 1 ? '审核通过' : '已拒绝');
                    this.getList();
                })
            }).catch(() => {
                this.$modal.msgError('已取消审核');
            });

        },

        getSupplierAllList() {
            getSupplierAllList({ type: 0 }).then(res => {
                this.supplierList = res;
            });
        },
    },
};
</script>
<style type="text/css" scoped>
.box-card {
    margin-top: 10px;
}
</style>
<style type="text/css">
.form-demo .el-form-item .el-form-item__content {
    width: 215px;
}
</style>